package com.example.job.model;

import com.example.job.IJob;
import com.example.utils.reflect.ReflectUtils;

import java.lang.reflect.Method;
import java.util.List;

/**
 * @Classname IJobModel
 * @Description TODO
 * @Date 2022/8/2 11:42
 * @Created by XiongXiong
 * @Author: X.I.O
 */
public class IJobModel implements IJob {

    private Class<?> cls;

    private Method method;

    private int secords;

    private String jobName;

    private String jobGroupName;

    private String tiggerName;

    private String tiggerGroup;

    public Class<?> getCls() {
        return cls;
    }

    public void setCls(Class<?> cls) {
        this.cls = cls;
    }

    private String getClsName() {
        if(cls!=null){
            return this.cls.getName();
        }
        return "";
    }

    @Override
    public String getJobName() {
        if(this.jobName!=null){
            return this.jobName;
        }
        return getClsName();
    }

    @Override
    public String getJobGroup() {
        if (this.jobGroupName != null) {
            return this.jobGroupName;
        }
        return getClsName();
    }

    @Override
    public String getTiggerName() {
        if(this.tiggerName!=null){
            return this.tiggerName;
        }
        return getClsName();
    }

    @Override
    public String getTiggerGroup() {
        if(this.tiggerGroup!=null){
            return this.tiggerGroup;
        }
        return getClsName();
    }

    @Override
    public int getExecuteSecords() {
        return this.secords;
    }

    @Override
    public void execute() {
        if(method!=null && this.cls!=null){
            Object obj=ReflectUtils.getNewInstance(this.cls);
            try {
                method.invoke(obj);
            }catch (Exception e) {
                e.printStackTrace();
            }
        }
    }


    public Method getMethod() {
        return method;
    }

    public void setMethod(Method method) {
        this.method = method;
    }



    public IJobModel(Class<?> cls, Method method, int secords, String jobName, String jobGroupName, String tiggerName, String tiggerGroup) {
        this.cls = cls;
        this.method = method;
        this.secords = secords;
        this.jobName = jobName;
        this.jobGroupName = jobGroupName;
        this.tiggerName = tiggerName;
        this.tiggerGroup = tiggerGroup;
    }
}
